package com.situ.project1.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.situ.project1.mapper.CarMapper;
import com.situ.project1.pojo.Car;
import com.situ.project1.pojo.search.CarSearchModel;
import com.situ.project1.service.CarService;
import com.situ.project1.util.PaginateInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author:yzy
 * @date:2024/8/10
 */
@Service
public class CarServiceImpl implements CarService {
    private CarMapper carMapper;
    @Autowired
    public CarServiceImpl(CarMapper carMapper) {
        this.carMapper = carMapper;
    }

    @Override
    public List<Car> findAll(PaginateInfo pi, CarSearchModel car) {
        try (Page<Car> __ = PageHelper.startPage(pi.getPageNo(), pi.getPageSize())){
            boolean tmp = carMapper.updateOrderCount();
            return carMapper.findAll(car);
        }

    }

    @Override
    public boolean add(Car car) {
        return carMapper.add(car);
    }

    @Override
    public boolean update(Car car) {
        return carMapper.update(car);
    }

    @Override
    public boolean delete(Integer[] ids) {
        return carMapper.delete(ids);
    }

    @Override
    public List<Car> findRest() {
        return carMapper.findRest();
    }

    @Override
    public List<Car> findRestCar(LocalDateTime startTime, LocalDateTime endTime) {
        return carMapper.findRestCar(startTime,endTime);
    }
}
